<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2023-01-29 13:58:42
 * @LastEditors: 李天惊 uf_lee@163.com
 * @LastEditTime: 2023-08-03 14:16:57
 * @FilePath: \zhmc\pc\sys\src\views\UserCenter\User\components\Edit.vue
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<script setup lang="ts">
import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
import { TableData } from '@/api/role/types'
import { required } from '@/utils/formRules'

const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<TableData>>,
    default: () => null
  }
})

const rules = reactive({
  role_name: [required],
  is_stop: [required]
})

const schema = reactive<FormSchema[]>([
  {
    component: 'Input',
    field: 'username',
    label: '用户名',
    componentProps: {
      disabled: true
    }
  },
  { component: 'Input', field: 'nickname', label: '姓名' },
  { component: 'Input', field: 'email', label: '电子邮箱' },
  { component: 'Input', field: 'mobile', label: '手机号' }
  // {
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: '启用', value: '0' },
  //       { label: '停用', value: '1' }
  //     ]
  //   },
  //   field: 'is_stop',
  //   label: '是否停用'
  // }
])

const { register, methods, elFormRef } = useForm({
  schema: schema
})

watch(
  () => props.currentRow,
  (currentRow) => {
    if (!currentRow) return
    const { setValues } = methods
    setValues(currentRow)
  },
  {
    deep: true,
    immediate: true
  }
)

defineExpose({
  elFormRef,
  getFormData: methods.getFormData
})
</script>

<template>
  <Form :rules="rules" @register="register" />
</template>
